﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.IO;
using FJASPX.Framwork.Constant;

namespace FJASPX.Framwork.Cache
{
    public static class AutoExecution
    {
        /// <summary>
        /// 开启同步线程
        /// </summary>
        public static void StartApp()
        {
            ThreadStart ts = new ThreadStart(Task);
            Thread t = new Thread(ts);
            t.Start();
        }

        private static DateTime deleTime;

        private static DirectoryInfo diri;

        /// <summary>
        /// 任务
        /// </summary>
        private static void Task()
        {
            Thread.Sleep(10000);
            //删除缓存图片
            deleTime = DateTime.Now.AddDays(-1);
            diri = new DirectoryInfo(Cfg.CACHE_PATH);
            foreach (FileInfo fli in diri.GetFiles())
            {
                if (fli.CreationTime < deleTime)
                {
                    fli.Delete();
                }
            }
            Task();
        }
    }
}